package com.darwin.darwinDll.core
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * 远程文件加载器
	 * @author Roland
	 */
	public class RemoteURLLoader extends EventDispatcher implements IURLLoader
	{
		private var _urlLoader:URLLoader;
		/**
		 *	实例化一个远程文件加载器 
		 * 
		 */
		public function RemoteURLLoader()
		{
			super(null);
			_urlLoader = new URLLoader();
			_urlLoader.addEventListener(Event.COMPLETE,onEvent);
			_urlLoader.addEventListener(ProgressEvent.PROGRESS,onEvent);
			_urlLoader.addEventListener(IOErrorEvent.IO_ERROR,onEvent);
		}
		
		public function load(url:String):void
		{
			var request:URLRequest = new URLRequest(url);
			_urlLoader.load(request);
		}
		
		protected function onEvent(event:Event):void
		{
			dispatchEvent(event);
		}
		
		public function close():void
		{
			_urlLoader.close();
		}
		
		public function get bytesLoaded():uint
		{
			return _urlLoader.bytesLoaded;
		}
		
		public function get bytesTotal():uint
		{
			return _urlLoader.bytesTotal;
		}
		
		public function get data():*
		{
			return _urlLoader.data;
		}
		
		public function get dataFormat():String
		{
			return _urlLoader.dataFormat;
		}
		
		public function set dataFormat(value:String):void
		{
			_urlLoader.dataFormat = value;
		}
	}
}